package com.transitionseverywhere;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import com.transitionseverywhere.Transition;
import com.transitionseverywhere.utils.AnimatorUtils;

/* loaded from: classes.dex */
public class Fade extends Visibility {
    public static final int IN = 1;
    public static final int OUT = 2;
    static final String PROPNAME_ALPHA = "fade:alpha";

    public Fade() {
    }

    public Fade(int i) {
        setMode(i);
    }

    public Fade(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.Fade);
        int i = obtainStyledAttributes.getInt(R.styleable.Fade_fadingMode, getMode());
        obtainStyledAttributes.recycle();
        setMode(i);
    }

    @Override // com.transitionseverywhere.Visibility, com.transitionseverywhere.Transition
    public void captureStartValues(TransitionValues transitionValues) {
        super.captureStartValues(transitionValues);
        if (transitionValues.view != null) {
            transitionValues.values.put(PROPNAME_ALPHA, Float.valueOf(transitionValues.view.getAlpha()));
        }
    }

    private Animator createAnimation(final View view, float f, float f2, TransitionValues transitionValues) {
        final float alpha = view.getAlpha();
        float f3 = f * alpha;
        float f4 = f2 * alpha;
        if (transitionValues != null && transitionValues.values.containsKey(PROPNAME_ALPHA)) {
            float floatValue = ((Float) transitionValues.values.get(PROPNAME_ALPHA)).floatValue();
            if (floatValue != alpha) {
                f3 = floatValue;
            }
        }
        view.setAlpha(f3);
        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(view, View.ALPHA, f4);
        ofFloat.addListener(new FadeAnimatorListener(view, alpha));
        addListener(new Transition.TransitionListenerAdapter() { // from class: com.transitionseverywhere.Fade.1
            @Override // com.transitionseverywhere.Transition.TransitionListenerAdapter, com.transitionseverywhere.Transition.TransitionListener
            public void onTransitionEnd(Transition transition) {
                view.setAlpha(alpha);
            }
        });
        return ofFloat;
    }

    @Override // com.transitionseverywhere.Visibility
    public Animator onAppear(ViewGroup viewGroup, View view, TransitionValues transitionValues, TransitionValues transitionValues2) {
        return createAnimation(view, 0.0f, 1.0f, transitionValues);
    }

    @Override // com.transitionseverywhere.Visibility
    public Animator onDisappear(ViewGroup viewGroup, View view, TransitionValues transitionValues, TransitionValues transitionValues2) {
        return createAnimation(view, 1.0f, 0.0f, transitionValues);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class FadeAnimatorListener extends AnimatorListenerAdapter {
        private float mEndListenerAlpha;
        private boolean mLayerTypeChanged = false;
        private final View mView;

        public FadeAnimatorListener(View view, float f) {
            this.mView = view;
            this.mEndListenerAlpha = f;
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationStart(Animator animator) {
            if (AnimatorUtils.hasOverlappingRendering(this.mView) && this.mView.getLayerType() == 0) {
                this.mLayerTypeChanged = true;
                this.mView.setLayerType(2, null);
            }
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            this.mView.setAlpha(this.mEndListenerAlpha);
            if (this.mLayerTypeChanged) {
                this.mView.setLayerType(0, null);
            }
        }
    }
}
